package app.util.image.action.morph
{
	import app.util.*;
	import app.util.image.*;
	import app.util.image.action.*;
	import app.util.image.calc.*;
	
	import flash.display.*;

	public class OpenAction extends SEBasedAction
	{
		private var first:Boolean = true;
		private var ret:BinaryBitmapData;
		
		public override function getDescription():String
		{
			return "Binary Openning";
		}
		
		protected override function getFinalBitmapData():BitmapData
		{
			return this.ret.toBitmapData();
		}
		
		protected override function processBitmapDataByStep():Number
		{
			if(this.first)
			{
				var src:BitmapData = Mediator.getCurrentBitmapData();
				var biSrc:BinaryBitmapData = MorphUtility.autoThreshold(src);
				this.ret = MorphUtility.doErosion(biSrc, se);
				this.first = false;
				return 0.5;
			}
			else
			{
				this.ret = MorphUtility.doDilation(this.ret, se);
				return 1;
			}
		}
	}
}